package com.example.administrator.foodrowfresh.configs.classifyconfing.classifyadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.superBase.MyBaseAdapter;

import org.xutils.x;

import java.util.List;
import java.util.Map;

/**
 * Created by lqr on 2016/5/2.
 */
public class MyGridViewAdapter extends MyBaseAdapter<Map<String,String>> {
    private List<Map<String, String>> list;
    private Context mContext;

    public MyGridViewAdapter(List<Map<String, String>> list, Context mContext) {
        super(list, mContext);
        this.list=list;
        this.mContext=mContext;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.layout_grid_item,parent,false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(list.get(position).get("sCategoryName"));
        //设置隐藏的Id
        holder.idTextView.setText(list.get(position).get("sCategoryId"));
        //获取右边布局图片的地址

        String pictureUrl = list.get(position).get("pictureUrl");
        x.image().bind(holder.imageView,pictureUrl);
        return convertView;
    }

    public class ViewHolder{
        TextView textView;
        TextView idTextView;
        ImageView imageView;

        public ViewHolder(View view) {
            textView= (TextView) view.findViewById(R.id.grid_text);
            imageView= (ImageView) view.findViewById(R.id.grid_image);
            idTextView= (TextView) view.findViewById(R.id.grid_id);
        }
    }
}
